package com.lixinyu.springboot.controller;

import com.lixinyu.springboot.Service.UserService;
import com.lixinyu.springboot.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping(value = "/user")
public class UserContrller {
    @Autowired
    private UserService userService;

    @RequestMapping(value = "/login")
    @ResponseBody
    public int getlogin(@RequestParam(value = "name") String name, @RequestParam(value = "password") String password) {
        System.out.println(name+"姓名为多少");
        System.out.println(password+"密码为多少");
        User u = new User(name,password);
        int i = userService.login(u);
        return i;
    }

    @RequestMapping("/index")
    public String index() {
        return "/Login";
    }

    @RequestMapping("/success")
    public String success() {
        return "success";
    }

    @RequestMapping("/Usermanage")
    public String Usermanage() {
        return "Usermanage";
    }

    @RequestMapping("/Add")
    public String Add(@RequestParam(value = "name") String name, @RequestParam(value = "password") String password) {
        System.out.println(name + "账号");
        System.out.println(password + "密码");
        User user = new User(name, password);
        userService.Add(user);

        return "success";
    }

    @RequestMapping("/add")
    public String add() {
        return "Add";
    }

    @RequestMapping("/userlist")
    @ResponseBody
    public List<User> userlsit() {
        List<User> user = userService.Userlist();

        return user;
    }

    @RequestMapping("/getuserlist")
    public String getuserlsit() {


        return "UserList";
    }


    @RequestMapping("/Add2")
    public String Add2(@RequestParam(value = "name") String name, @RequestParam(value = "password") String password) {
        userService.Add2(name, password);
        return "success";
    }


    @RequestMapping(value = "/AdminIndex")
    public  String getAdminIndex(){
        return  "/AdminIndex";
    }

  @RequestMapping(value = "/userList")
  @ResponseBody
    public  List getUserList(){

        List<User> userlist = new ArrayList<User>();
      userlist = userService.Userlist();
        return userlist;

  }


    @RequestMapping(value = "/main")
    public  String main(){


        return "main";

    }


}
